package com.zmsoft.boxy.sfg;

import javax.annotation.Resource;

import org.cnsoft.framework.json.JSONObject;
import org.cnsoft.framework.support.MyServiceSupport;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.zmsoft.boxy.sfg.player.SFGGameConstants;
import com.zmsoft.persistent.sfg.Sfg661010PlayerFarm.Sfg661010PlayerFarmDBO;
import com.zmsoft.persistent.sfg.Sfg661010PlayerFarm.Sfg661010PlayerFarmDao;
import com.zmsoft.persistent.sfg.Sfg661021PlayerLand.Sfg661021PlayerLandDBO;
import com.zmsoft.persistent.sfg.Sfg661021PlayerLand.Sfg661021PlayerLandDao;
import com.zmsoft.persistent.sfg.Sfg661030PlayerWarehouse.Sfg661030PlayerWarehouseDBO;
import com.zmsoft.persistent.sfg.Sfg661030PlayerWarehouse.Sfg661030PlayerWarehouseDao;
import com.zmsoft.persistent.sfg.Sfg661040PlayerPocket.Sfg661040PlayerPocketDBO;
import com.zmsoft.persistent.sfg.Sfg661040PlayerPocket.Sfg661040PlayerPocketDao;

/**
 * 玩家数据缓存服务
 */
@Service("MySFGPlayerDataPersistentService")
//@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class MySFGPlayerDataPersistentService extends MyServiceSupport implements SFGGameConstants {

	@Resource
	private Sfg661010PlayerFarmDao daoSfg661010PlayerFarm;
	@Resource
	private Sfg661021PlayerLandDao daoSfg661021PlayerLand;
	@Resource
	private Sfg661030PlayerWarehouseDao daoSfg661030PlayerWarehouse;
	@Resource
	private Sfg661040PlayerPocketDao daoSfg661040PlayerPocket;

	// 设置启动模式-每分钟启动
	@Scheduled(cron = "0/5 * * * * ?")
	public void doQuartzService() throws Exception {
		// 数据处理队列- 游戏数据落地入库队列
		String gameData = myCacheService.pollFirstObjectInList(SFG_GAME_PLAYER_DATA);
		// 数据转换
		Object gameDataObject = JSONObject.parseObject2(gameData);
		// 农场数据
		if (gameDataObject instanceof Sfg661010PlayerFarmDBO) {
			daoSfg661010PlayerFarm.doUpdate((Sfg661010PlayerFarmDBO) gameDataObject);
		}
		// 农场数据
		else if (gameDataObject instanceof Sfg661021PlayerLandDBO) {
			daoSfg661021PlayerLand.doInsertOrUpdate((Sfg661021PlayerLandDBO) gameDataObject);
		}
		// 仓库数据
		else if (gameDataObject instanceof Sfg661030PlayerWarehouseDBO) {
			daoSfg661030PlayerWarehouse.doInsertOrUpdate((Sfg661030PlayerWarehouseDBO) gameDataObject);
		}
		// 口袋数据
		else if (gameDataObject instanceof Sfg661040PlayerPocketDBO) {
			daoSfg661040PlayerPocket.doInsertOrUpdate((Sfg661040PlayerPocketDBO) gameDataObject);
		}
	}
}
